home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / misc~1 / 2 / convert2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-11-19  |  5.5 KB  |  185 lines

  1. { ----------------------- ST/XE Text File Converter 2 ----------------------- }
  2. { ----------- utility to convert atascii text files to pure ascii ----------- }
  3. { ------------------- (ignores all ctrl chars except eol) ------------------- }
  4. {                                                                             }
  5. { ----------- by Craig Dickson, Sequoia Software, 9 February 1986 ----------- }
  6. { ---------------------- Written in OSS Personal Pascal --------------------- }
  7. {                                                                             }
  8. { ----------- This program is Copyright (c) 1986 Sequoia Software. ---------- }
  9. { -- It may be freely distributed among users of Atari ST-series computers -- }
  10. { ---------- provided only that it is not to be modified in any way --------- }
  11. { ------------------ without the permission of the author. ------------------ }
  12.  
  13. program convert_prg ;
  14.  
  15.   const
  16.  
  17.     {$I gemconst.pas}
  18.  
  19.     as_cr =      13 ;
  20.     as_lf =      10 ;
  21.     at_eol =    155 ;
  22.     ignore =      1 ;
  23.     low =        32 ;
  24.     mask =      127 ;
  25.     space =      32 ;
  26.     soft_space = 30 ;
  27.  
  28.   type
  29.  
  30.     {$I gemtype.pas}
  31.  
  32.     txt_buf = array[ 1..12288 ] of char ;
  33.  
  34.   var
  35.     first_word : boolean ;
  36.     ch,
  37.     dummy,
  38.     mode,
  39.     twhich,
  40.     which : integer ;
  41.     bin_path,
  42.     bin_title,
  43.     out_title : path_name ;
  44.     alert : str255 ;
  45.     bin_file,
  46.     out_file : text ;
  47.     buffer : txt_buf ;
  48.  
  49.   {$I gemsubs.pas}
  50.  
  51.   procedure show_off ;
  52.     begin
  53.       alert := '[0][ST/XE Text  File Converter 2|      by Craig Dickson' ;
  54.       alert := concat( alert, '| | Compuserve PPN: 72257,1604| ]' ) ;
  55.       alert := concat( alert, '[  OK  ]' ) ;
  56.       dummy := do_alert( alert, 1 ) ;
  57.       alert := '[0][ (C) 1986  Sequoia Software.|Portions of ' ;
  58.       alert := concat( alert, 'this product are|    (C) 1986 OSS ' );
  59.       alert := concat( alert, 'and CCD.| Used by  Permission of OSS.| ]' ) ;
  60.       alert := concat( alert, '[  OK  ]' ) ;
  61.       dummy := do_alert( alert, 1 ) ;
  62.       alert := '[0][This program is not to be sold|but may be ' ;
  63.       alert := concat( alert, ' distributed freely|   provided only ' );
  64.       alert := concat( alert, 'that it is|      in no way modified.| ]' ) ;
  65.       alert := concat( alert, '[  NO PROBLEM  ]' ) ;
  66.       dummy := do_alert( alert, 1 ) ;
  67.     end ;
  68.  
  69.   procedure set_titles ;
  70.     begin
  71.       alert := '[2][Convert a file or quit?][ Convert | Quit ]' ;
  72.       mode := do_alert( alert, 2 ) ;
  73.       if mode <> 2 then
  74.       begin
  75.         alert := '[2][Convert to 1st Word format?][ Yes | No ]' ;
  76.         first_word := (do_alert( alert, 2 ) = 1) ;
  77.         bin_path := 'A:*.*' ;
  78.         if length( bin_title ) > 0 then
  79.           delete( bin_title, 1, length( bin_title ) ) ;
  80.         if length( out_title ) > 0 then
  81.           delete( out_title, 1, length( out_title ) ) ;
  82.         if get_in_file( bin_path, bin_title ) then
  83.           if not get_out_file( 'Enter output pathname:', out_title ) then
  84.             mode := 2 ;
  85.       end ;
  86.     end ;
  87.  
  88.   procedure translate ;
  89.  
  90.     procedure op_files ;
  91.       begin
  92.         reset( bin_file, bin_title ) ;
  93.         rewrite( out_file, out_title ) ;
  94.       end ;
  95.  
  96.     procedure cl_files ;
  97.       begin
  98.         close( bin_file ) ;
  99.         close( out_file ) ;
  100.       end ;
  101.  
  102.     procedure load_file ;
  103.       begin
  104.         which := 0 ;
  105.         repeat
  106.           which := which + 1 ;
  107.           if not eof( bin_file ) then
  108.             begin
  109.               read( bin_file, buffer[ which ] ) ;
  110.               if (buffer[ which ] = chr( at_eol )) then
  111.                 which := which + 1 ;
  112.             end
  113.           else buffer[ which ] := chr( as_cr ) ;
  114.         until (eof( bin_file )) or (which > 12287) ;
  115.       end ;
  116.  
  117.     procedure save_file ;
  118.       begin
  119.         twhich := 0 ;
  120.         repeat
  121.           twhich := twhich + 1 ;
  122.           if buffer[ twhich ] <> chr( ignore ) then
  123.             write( out_file, buffer[ twhich ] ) ;
  124.         until twhich = which ;
  125.       end ;
  126.  
  127.     procedure load_ch ;
  128.       begin
  129.         ch := ord( buffer[ twhich ] ) ;
  130.         if ch <> at_eol then
  131.           ch := ch & mask ;
  132.       end ;
  133.  
  134.     procedure save_ch( ch_p : integer ) ;
  135.       begin
  136.         buffer[ twhich ] := chr( ch_p ) ;
  137.       end ;
  138.  
  139.     begin { translate }
  140.       op_files ;
  141.       repeat
  142.         load_file ;
  143.         twhich := 0 ;
  144.         repeat
  145.           twhich := twhich + 1 ;
  146.           load_ch ;
  147.           case ch of
  148.             at_eol : begin
  149.                        save_ch( as_cr ) ;
  150.                        twhich := twhich + 1 ;
  151.                        save_ch( as_lf ) ;
  152.                      end ;
  153.             space  : begin
  154.                        if first_word then
  155.                          save_ch( soft_space )
  156.                        else save_ch( space ) ;
  157.                      end ;
  158.             otherwise : begin
  159.                           if ch < low then
  160.                             save_ch( ignore )
  161.                           else save_ch( ch ) ;
  162.                         end ;
  163.           end ;
  164.         until twhich = which ;
  165.         save_file ;
  166.       until eof( bin_file ) ;
  167.       cl_files ;
  168.     end ;
  169.  
  170.   begin { convert_prg }
  171.     if init_gem >= 0 then
  172.       begin
  173.         show_off ;
  174.         repeat
  175.           set_titles ;
  176.           if mode <> 2 then
  177.             translate ;
  178.         until mode = 2 ;
  179.       exit_gem ;
  180.       end ;
  181.   end.
  182.  
  183. { ---------------------------- end of convert_prg --------------------------- }
  184.